#ifndef CREATECONNECTION_H
#define CREATECONNECTION_H

#include<QSqlDatabase>
#include<QCoreApplication>
#include<QFile>
#include<QSysInfo>
#include<QtGlobal>
#include<QDebug>

static bool CreateConnection(){
    //打印可用sql驱动
    //    qDebug()<<"可用驱动:";
    //    QStringList drivers = QSqlDatabase::drivers();
    //    for(auto driver: drivers){
    //        qDebug()<<driver<<" ";
    //    }
    //设置数据库驱动
    QSqlDatabase db1 = QSqlDatabase::addDatabase("QSQLITE", "connection1");

    //根据系统环境设计数据库路径
//Q_OS_IOS： Q_PROCESSOR_ARM： Q_OS_LINUX：Q_OS_WIN：   Q_OS_WIN32
#ifdef Q_OS_MAC
    ////数据库放在运行文件的目录下
    /// 例如：F:\code\build-DeepLearningPictureDescription-Desktop_Qt_5_15_2_MinGW_32_bit-Release\release\database
    // /Users/mac/Qt/DeepLearningPictureDescription
    db1.setDatabaseName("/Users/mac/Qt/DeepLearningPictureDescription/database/DeepLearningPictureDescriptionSystem.db");
#endif
#ifdef Q_OS_WIN //Q_OS_WIN32
    db1.setDatabaseName(QCoreApplication::applicationDirPath() + QString("/database/DeepLearningPictureDescriptionSystem.db"));
#endif

    //打开数据库
    if(!db1.open()){
        return false;
    }


    return true;
}



#endif // CREATECONNECTION_H
